Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@turf/truncate
Advanced tools
@turf/truncate is a module in the Turf.js library that is used to truncate the precision of coordinates in GeoJSON data. This can be useful for reducing the size of GeoJSON files or for ensuring consistent precision across datasets.
Truncate Coordinates
This feature allows you to truncate the coordinates of a GeoJSON object to a specified precision. In this example, the coordinates of a point are truncated to 3 decimal places.
const truncate = require('@turf/truncate');
const point = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [70.123456789, 40.987654321] } };
const truncated = truncate(point, { precision: 3 });
console.log(truncated);
Truncate with Custom Options
This feature allows you to truncate the coordinates of a GeoJSON object with custom options. In this example, the coordinates of a LineString are truncated to 2 decimal places, and the number of coordinates is also limited to 2.
const truncate = require('@turf/truncate');
const lineString = { "type": "Feature", "geometry": { "type": "LineString", "coordinates": [[70.123456789, 40.987654321], [71.123456789, 41.987654321]] } };
const truncated = truncate(lineString, { precision: 2, coordinates: 2 });
console.log(truncated);
The geojson-precision package allows you to set the precision of GeoJSON coordinates. It is similar to @turf/truncate in that it helps reduce the size of GeoJSON files by limiting the number of decimal places in coordinates. However, it is a standalone package and not part of a larger geospatial library like Turf.js.
The simplify-geojson package is used to simplify GeoJSON geometries by reducing the number of points in the geometries. While it does not specifically truncate coordinate precision, it serves a similar purpose of reducing the size and complexity of GeoJSON data. It is more focused on simplifying shapes rather than just truncating coordinates.
Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.
Parameters
layer
(Feature | FeatureCollection) any GeoJSON Feature or FeatureCollectionprecision
[number] coordinate decimal precision (optional, default 6
)coordinates
[number] maximum number of coordinates (primarly used to remove z coordinates) (optional, default 2
)Examples
var point = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
70.46923055566859,
58.11088890802906,
1508
]
},
"properties": {}
};
var pointTrunc = turf.truncate(point);
//= pointTrunc
Returns (Feature | FeatureCollection) layer with truncated geometry
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Install this module individually:
$ npm install @turf/truncate
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
FAQs
turf truncate module
The npm package @turf/truncate receives a total of 503,786 weekly downloads. As such, @turf/truncate popularity was classified as popular.
We found that @turf/truncate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.